/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade.modules.system.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.modules.system.entity.Drugs;
import org.springblade.modules.system.entity.DrugsType;
import org.springblade.modules.system.service.IDrugsService;
import org.springblade.modules.system.service.IDrugsTypeService;
import org.springblade.utils.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 控制器
 *
 * @author Chill
 */
@Api("drugs")
@Controller
@RequestMapping("/drugs")
public class DrugsController{
	@Autowired
	private IDrugsService drugsService;
	@Autowired
	private IDrugsTypeService drugsTypeService;

	/**
	 *
	 * @param drugs
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@ResponseBody
	@ApiOperation(value = "显示所有")
	@RequestMapping(value = "/openDrugsTable", method = RequestMethod.POST)
	public HashMap<String, Object> openDrugsTable(Drugs drugs,int pageSize,int currentPage) throws Exception {
		HashMap<String,Object> result = new HashMap<>();
		PageBounds<Drugs> pageBounds = drugsService.showAllDrugs(drugs, currentPage,pageSize);
		result.put("data", pageBounds);
		return result;
	}
	/**
	 * 增加药品
	 * @param drugs
	 * @return
	 */
	@ResponseBody
	@ApiOperation(value = "新增药品")
	@RequestMapping(value = "/addDrugs",method = RequestMethod.POST)
	public HashMap<String,Object> addDrugs(Drugs drugs){
		drugsService.addDrugs(drugs);
		return new HashMap<>();
	}
	/**
	 * 删除
	 *
	 * @param id
	 * @return
	 */
	/*@RequestMapping(value = "/delDrugs",method = RequestMethod.POST)
	public R<Object> delDrugs(Integer id) {
		int m=drugsService.deleteDrugs(id);
		return R.status(m>0);
	}*/
	/**
	 * 修改药品
	 * @param drugs
	 * @return
	 */
	@ResponseBody
	@ApiOperation(value = "修改药品")
	@RequestMapping(value = "/updateDrugs",method = RequestMethod.POST)
	public HashMap<String,Object> updateDrugs(Drugs drugs){
		drugsService.updateDrugs(drugs);
		return new HashMap<>();
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@ResponseBody
	@ApiOperation(value = "批量删除")
	@RequestMapping(value = "/deleteDrugsByIds", method = RequestMethod.POST)
	public HashMap<String, Object> deleteMoreDrugs(Integer[] ids){
		HashMap<String,Object> result = new HashMap<>();
		drugsService.deleteMoreDrugs(Arrays.asList(ids));
		return result;
	}

	/**
	 * 动态显示类别下拉框
	 * @param drugsType
	 * @return
	 */
	@ResponseBody
	@ApiOperation(value = "显示分类")
	@RequestMapping(value = "/getAllDrugsType", method = RequestMethod.POST)
	public HashMap<String, Object> getAllDrugsType(DrugsType drugsType) {
		HashMap<String, Object> result = new HashMap<>();
		List<DrugsType> list = drugsTypeService.getAllDrugsType(drugsType);
		result.put("data", list);
		return result;
	}

}
